﻿using Catalogo.Portable.DataSources;
using Catalogo.Portable.Model;
using Catalogo.Portable.ViewModel.Commands;
using Catalogo.Portable.ViewModel.Messages;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Xml;

namespace Catalogo.Portable.ViewModel
{
    public class CategoriaPageViewModel : ViewModelBase
    {
        public ICommand AbrirHomeCommand { get; private set; }
        public ICommand AbrirItemCommand { get; private set; }

        private Categoria _Categoria;
        public Categoria Categoria
        {
            get { return _Categoria; }
            set { SetProperty(ref this._Categoria, value); }
        }

        private Empresa _Empresa;
        public Empresa Empresa
        {
            get { return _Empresa; }
            set { SetProperty(ref this._Empresa, value); }
        }

        public CategoriaPageViewModel()
        {
            AbrirHomeCommand = new DelegateCommand(OnAbrirHomeCommand);
            AbrirItemCommand = new DelegateCommand(OnAbrirItemCommand);
        }

        private void OnAbrirItemCommand(object obj)
        {
            PublishMessage<NavegarParaPagina>(new NavegarParaPagina("ItemPage", obj));
        }

        private void OnAbrirHomeCommand(object obj)
        {
            PublishMessage<NavegarParaPagina>(new NavegarParaPagina("HomePage", obj));
        }

        public async Task LoadAsync(string idCategoria)
        {
            Empresa = await CatalogoDataSource.Instance.ObterEmpresaAsync();
            Categoria = await CatalogoDataSource.Instance.ObterCategoriaAsync(idCategoria);
        }
    }
}
